#encoding=utf-8
'''
Created on 2014-12-9

@author: cooler
'''
import sys
reload(sys)
sys.setdefaultencoding('utf8')
import urllib2
import time
from datetime import datetime
import  logging,  os.path
logger = logging.getLogger('SMS')
logger.setLevel(logging.DEBUG)

def sendSMS(phone,content):
        #发送校验码
        url = "http://www.mxtong.net.cn/GateWay/Services.asmx/DirectSend?UserID=963123&Account=admin&Password=963123&Phones="
        url += str(phone)+";&Content="
        url += content+"&SendTime=&SendType=1&PostFixNumber="
        response = urllib2.urlopen(url) 
        html = response.read()
        html = html.replace("\n","").replace(" ","").replace("\r","");
        logger.info(html)
        if html.find("<OKPhoneCounts>1</OKPhoneCounts>")>0:
                return "1"
        else:
                return "0"
        # return html
        #return "1"

def initSMSQueue(mdb,phone,content,stype="verify_code"):
    data = {
        "phone":phone,
        "content":content,
        "createtime":datetime.now(),
        "lasttime":time.time(),
        "lastmodify":datetime.now(),
        "status":0,
        "send_status":0,
        "stype":stype,
    }
    mdb.beehoo_sms_queue.save(data)
    return "1"

if __name__ == '__main__':
        print time.time()
        content = "手机号码:13548617117的朋友在北京市海淀区中关村街道中关村文化体育中心，请求你安装壁虎安全（http://www.beehoo.cn）对她进行保护。【安全岛】"
        res = sendSMS("18511995224",content)
        print res
        print time.time()
